package review;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HomeWork {}

class A3{
    public static void main(String[] args) {
        int[] nums = {7,5,6,7,9,2,5,3,5};
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            int n=0;
            if(!list.contains(nums[i])){
                list.add(nums[i]);
            }
            else {
                continue;
            }
            for (int j = 0; j < nums.length; j++) {
                if (nums[i] == nums[j]) {
                    n++;
                }
            }
            System.out.println(nums[i]+"次数:"+n);
        }
    }
}

interface Animal{
    void makeSound();
}

class Dog implements Animal{
    @Override
    public void makeSound() {
        System.out.println("🐕在叫");
    }
}

class Cat implements Animal{
    @Override
    public void makeSound() {
        System.out.println("🐱在叫");
    }
}

class Cow implements Animal{
    @Override
    public void makeSound() {
        System.out.println("🐂在叫");
    }
}

class Zoo{
    List<Animal> animals = new ArrayList<>();
    void addAnimal(Animal animal){
        this.animals.add(animal);
    }
    void showAnimalsSound(){
        for (Animal animal : animals) {
            animal.makeSound();
        }
    }
    public static void main(String[] args) {
        Zoo zoo = new Zoo();
        zoo.addAnimal(new Dog());
        zoo.addAnimal(new Cat());
        zoo.addAnimal(new Cow());
        zoo.showAnimalsSound();
    }
}

class A4{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串:");
        String s = sc.nextLine();
        boolean flag = true;
        for (int i = 0; i < s.length()/2; i++){
            if (!(s.charAt(i) == s.charAt(s.length()-i-1))){
                System.out.println("不是回文字符串");
                flag = false;
                break;
            }
        }
        if (flag){
            System.out.println("是回文字符串");
        }
    }
}

class B4{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串:");
        String s = sc.nextLine();
        int n=1;
        String s1 = "";
        for (int i = 0; i < s.length(); i++){
            if(i+1==s.length()&&s.charAt(i) == s.charAt(i-1)){
                s1 = s1+s.charAt(i)+n;
                break;
            }
            else if(i+1==s.length()&&s.charAt(i) != s.charAt(i-1)){
                s1 = s1+s.charAt(i-1)+n;
                s1 = s1+s.charAt(i)+1;
                break;
            }
            if (s.charAt(i) == s.charAt(i+1)){
                n++;
            }
            else {
                s1 = s1+s.charAt(i)+n;
                n=1;
            }
        }
        if(s1.length()<s.length()){
            System.out.println(s1);
        }
        else {
            System.out.println(s);
        }
    }
}